package dth.bean;

import java.util.List;

import javax.faces.bean.ManagedBean;

import org.primefaces.model.chart.CartesianChartModel;
import org.primefaces.model.chart.ChartSeries;

import dth.dao.ReportDAO;
import dth.entity.ReportMovie;
import dth.entity.ReportPackage;
import dth.utils.DthUtil;

@ManagedBean(name = "chartBean")
public class ChartBean {
	private CartesianChartModel packageChart;
	private CartesianChartModel moivieChart;
	
	public CartesianChartModel getMoivieChart() {
		ReportDAO dao = new ReportDAO();
		List<ReportMovie> list = dao.getListReportMovie();
		if (list != null && list.size() > 0) {
			moivieChart = new CartesianChartModel();
			ChartSeries bo = new ChartSeries();
			bo.setLabel("movie");
			for (ReportMovie r : list) {
				bo.set(r.getMovieName(), r.getSumPrice());
			}
			moivieChart.addSeries(bo);
		}
		return moivieChart;
	}

	public void setMoivieChart(CartesianChartModel moivieChart) {
		this.moivieChart = moivieChart;
	}

	public CartesianChartModel getPackageChart() {
		ReportDAO dao = new ReportDAO();
		List<ReportPackage> list = dao.getListReportPackge();
		if (list != null && list.size() > 0) {
			packageChart = new CartesianChartModel();
			ChartSeries bo = new ChartSeries();
			bo.setLabel("");
			for (ReportPackage r : list) {
				bo.set(r.getPackName(), r.getSumPrice());
			}
			packageChart.addSeries(bo);
		}
		return packageChart;
	}

	public void setPackageChart(CartesianChartModel packageChart) {
		this.packageChart = packageChart;
	}
	public ChartBean() {
		// TODO Auto-generated constructor stub
		System.out.println("---request url:"+DthUtil.getRequestURL());
		if(DthUtil.getRequestURL().contains("report_book_movie.xhtml")||DthUtil.getRequestURL().contains("report_package_history.xhtml")){
			System.out.println("--vao day role:"+LoginBean.roleCode);
			if(LoginBean.roleCode!=1)
				DthUtil.navigateTo("welcome.xhtml");
		}
	}
}
